package gui.visu.components;

import gui.IHM;
import gui.edit.enums.E_InteractionModes;
import gui.utils.RadioButtonIcon;
import gui.visu.listeners.ListenerInteractionModeButton;

import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;

import javax.swing.ButtonGroup;
import javax.swing.JLabel;
import javax.swing.JPanel;

import tuio.components.RadioButtonTouch;

import data.Constants;



/**
 * @author Charles Perin
 * 29 mars 2011
 * LIMSI - INRIA Rennes
 * charles.perin@free.fr
 *
 */
public class DisplayDataOptionPanelDown extends JPanel{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 5540349328538677087L;

	private IHM ihm;
	
	public DisplayDataOptionPanelDown(IHM parent){
		this.setIhm(parent);
		buildCurveOptionPanelDown();
	}
	
	
	private void buildCurveOptionPanelDown(){
		GridBagConstraints c = new GridBagConstraints();
		c.gridx=0;
		c.gridy=0;
		this.setLayout(new GridBagLayout());
		
		this.add(buildModePane(),c);
	}

	private JPanel buildModePane(){
		JPanel modePane = new JPanel(new GridBagLayout());
		modePane.setName("modePane");
		GridBagConstraints c = new GridBagConstraints();
		c.insets = Constants.INSETS_DEFAULT;
		c.gridx=0;
		c.gridy=0;
		c.gridwidth=4;
		JLabel modeLabel = new JLabel("Mode: ");
		modeLabel.setFont(Constants.OPTION_PANE_FONT);
		modePane.add(modeLabel,c);

		c.gridwidth=1;
		c.gridy=c.gridy+1;
		c.fill=GridBagConstraints.NONE;
		c.gridwidth=1;
		
		Dimension dimRadio = new Dimension(50,45);
		
		RadioButtonTouch modifyButton = new RadioButtonTouch(new RadioButtonIcon("mode_edit", true));
		modifyButton.addActionListener(new ListenerInteractionModeButton(ihm.getDataControl(), E_InteractionModes.EDIT));
		modifyButton.setPreferredSize(dimRadio);
		modePane.add(modifyButton,c);

		c.gridx+=1;
		RadioButtonTouch stopButton = new RadioButtonTouch(new RadioButtonIcon("mode_stop", true));
		stopButton.addActionListener(new ListenerInteractionModeButton(ihm.getDataControl(), E_InteractionModes.STOP));
		stopButton.setPreferredSize(dimRadio);
		modePane.add(stopButton,c);
		
		c.gridx+=1;
		RadioButtonTouch playButton = new RadioButtonTouch(new RadioButtonIcon("mode_play", true));
		playButton.addActionListener(new ListenerInteractionModeButton(ihm.getDataControl(), E_InteractionModes.PLAY));
		playButton.setPreferredSize(dimRadio);
		modePane.add(playButton,c);
		
		c.gridx+=1;
		RadioButtonTouch pauseButton = new RadioButtonTouch(new RadioButtonIcon("mode_pause", true));
		pauseButton.addActionListener(new ListenerInteractionModeButton(ihm.getDataControl(), E_InteractionModes.PAUSE));
		pauseButton.setPreferredSize(dimRadio);
		modePane.add(pauseButton,c);
		
		ButtonGroup group = new ButtonGroup();
		group.add(playButton);
		group.add(modifyButton);
		group.add(stopButton);
		group.add(pauseButton);
		
		stopButton.setSelected(true);
		
		return modePane;
	}


	public void setIhm(IHM ihm) {
		this.ihm = ihm;
	}


	public IHM getIhm() {
		return ihm;
	}
}
